package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.Map; 
 import com.opensymphony.xwork2.ActionContext; 
import java.util.Collection; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblQLDTTXAThoiKhoaBieuDuKien;
import com.lb.jwitter.service.TblQLDTTXAThoiKhoaBieuDuKienService;
import com.lb.jwitter.service.TblQLDTTXADMNgayTrongTuan;
import com.lb.jwitter.service.TblQLDTTXADMNgayTrongTuanService;

import com.lb.jwitter.service.TblQLDTTXADMPhong;
import com.lb.jwitter.service.TblQLDTTXADMPhongService;

import com.lb.jwitter.service.TblQLDTTXADMTietHoc;
import com.lb.jwitter.service.TblQLDTTXADMTietHocService;

import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNam;
import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNamService;

import com.lb.jwitter.service.TblQLDTTXALopMonHocDuKien;
import com.lb.jwitter.service.TblQLDTTXALopMonHocDuKienService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAThoiKhoaBieuDuKienUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private int ngayId; 
    public void setNgayId(int ngayId) {
       this.ngayId = ngayId;
 }

    public int getNgayId() {
       return ngayId;
 }

    private TblQLDTTXADMNgayTrongTuanService tblQLDTTXADMNgayTrongTuanService; 

    private int phongId; 
    public void setPhongId(int phongId) {
       this.phongId = phongId;
 }

    public int getPhongId() {
       return phongId;
 }

    private TblQLDTTXADMPhongService tblQLDTTXADMPhongService; 

    private int tietHocId; 
    public void setTietHocId(int tietHocId) {
       this.tietHocId = tietHocId;
 }

    public int getTietHocId() {
       return tietHocId;
 }

    private TblQLDTTXADMTietHocService tblQLDTTXADMTietHocService; 

    private int hocKyId; 
    public void setHocKyId(int hocKyId) {
       this.hocKyId = hocKyId;
 }

    public int getHocKyId() {
       return hocKyId;
 }

    private TblQLDTTXAHocKyTrongNamService tblQLDTTXAHocKyTrongNamService; 

    private int lopMonHocDuKienId; 
    public void setLopMonHocDuKienId(int lopMonHocDuKienId) {
       this.lopMonHocDuKienId = lopMonHocDuKienId;
 }

    public int getLopMonHocDuKienId() {
       return lopMonHocDuKienId;
 }

    private TblQLDTTXALopMonHocDuKienService tblQLDTTXALopMonHocDuKienService; 

    private int daMoLop; 
    public void setDaMoLop(int daMoLop) {
       this.daMoLop = daMoLop;
 }

    public int getDaMoLop() {
       return daMoLop;
 }

    private TblQLDTTXAThoiKhoaBieuDuKien tblQLDTTXAThoiKhoaBieuDuKien; 
    public void setTblQLDTTXAThoiKhoaBieuDuKien (TblQLDTTXAThoiKhoaBieuDuKien tblQLDTTXAThoiKhoaBieuDuKien) {
        this.tblQLDTTXAThoiKhoaBieuDuKien = tblQLDTTXAThoiKhoaBieuDuKien;
 }

    private TblQLDTTXAThoiKhoaBieuDuKienService tblQLDTTXAThoiKhoaBieuDuKienService; 

	private int preUpdate(Message msg, TblQLDTTXAThoiKhoaBieuDuKien obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblQLDTTXAThoiKhoaBieuDuKien obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_ThoiKhoaBieuDuKien", "sua")){ 
        return "noprivilege"; 
    } 
        tblQLDTTXAThoiKhoaBieuDuKienService = (TblQLDTTXAThoiKhoaBieuDuKienService) context.getBean("tbl_QLDTTXA_ThoiKhoaBieuDuKienClient"); 
        tblQLDTTXADMNgayTrongTuanService = (TblQLDTTXADMNgayTrongTuanService) context.getBean("tbl_QLDTTXA_DM_NgayTrongTuanClient"); 

        tblQLDTTXADMPhongService = (TblQLDTTXADMPhongService) context.getBean("tbl_QLDTTXA_DM_PhongClient"); 

        tblQLDTTXADMTietHocService = (TblQLDTTXADMTietHocService) context.getBean("tbl_QLDTTXA_DM_TietHocClient"); 

        tblQLDTTXAHocKyTrongNamService = (TblQLDTTXAHocKyTrongNamService) context.getBean("tbl_QLDTTXA_HocKyTrongNamClient"); 

        tblQLDTTXALopMonHocDuKienService = (TblQLDTTXALopMonHocDuKienService) context.getBean("tbl_QLDTTXA_LopMonHoc_DuKienClient"); 

        msg = new Message(); 
        tblQLDTTXAThoiKhoaBieuDuKien = tblQLDTTXAThoiKhoaBieuDuKienService.gettblQLDTTXAThoiKhoaBieuDuKien(new Long(id)); 
        tblQLDTTXAThoiKhoaBieuDuKien.setNgayId(tblQLDTTXADMNgayTrongTuanService.gettblQLDTTXADMNgayTrongTuan(new Long(ngayId))); 
        tblQLDTTXAThoiKhoaBieuDuKien.setPhongId(tblQLDTTXADMPhongService.gettblQLDTTXADMPhong(new Long(phongId))); 
        tblQLDTTXAThoiKhoaBieuDuKien.setTietHocId(tblQLDTTXADMTietHocService.gettblQLDTTXADMTietHoc(new Long(tietHocId))); 
        tblQLDTTXAThoiKhoaBieuDuKien.setHocKyId(tblQLDTTXAHocKyTrongNamService.gettblQLDTTXAHocKyTrongNam(new Long(hocKyId))); 
        tblQLDTTXAThoiKhoaBieuDuKien.setLopMonHocDuKienId(tblQLDTTXALopMonHocDuKienService.gettblQLDTTXALopMonHocDuKien(new Long(lopMonHocDuKienId))); 
        if(daMoLop == 1){ 
           tblQLDTTXAThoiKhoaBieuDuKien.setDaMoLop(true); 
       } else { 
           tblQLDTTXAThoiKhoaBieuDuKien.setDaMoLop(false); 
       } 
        preUpdate(msg,tblQLDTTXAThoiKhoaBieuDuKien); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXAThoiKhoaBieuDuKienService.updatetblQLDTTXAThoiKhoaBieuDuKien(tblQLDTTXAThoiKhoaBieuDuKien); 
           postUpdate(msg, tblQLDTTXAThoiKhoaBieuDuKien); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_QLDTTXA_ThoiKhoaBieuDuKien Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
